<!-- 项目管理 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <p class="title-label mb10">重点企业</p>
    <dxtable :dataJson="dataJson" :portUrl="portUrl" :formJson="formJson" :qx="qx" ref="databale" :czFun="czFun"
      czWidth="220" @bjfun="bianjis"></dxtable>
    <!-- :czFun="czFun" -->
  </div>
</template>
<script lang='ts' setup>
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost } from "../../util/index";
import { NButton, NImage, NTag } from "naive-ui"
import { h, ref, reactive } from "vue";
const databale = ref();
const xmlxSelect = ref([])
const initeer = () => {
  databale.value.initDataExpose();
};
const sshhs = ref([])
let qxList = ref([]);
let dataJson = [
  {
    title: "封面",
    key: "cover",
    width: 60,
    render(row) {
      return h(NImage, { src: row.cover, class: "iconsder" })
    },
  },
  {
    title: "所属行业",
    key: "cid",
    type: "select",
    options: [],
    width: 100,
    search: true, // 是否在搜索栏展示
    render(row) {
      try {
        return sshhs.value.filter(a => a.value == row.cid)[0].label
      } catch (e) {
        return '--'
      }
    }
  },
  {
    title: "项目类型",
    key: "xmlx",
    type: "select",
    options: [],
    width: 100,
    search: true, // 是否在搜索栏展示
    render(row) {
      try {
        return xmlxSelect.value.filter(a => a.value == row.xmlx)[0].label
      } catch (e) {
        return '--'
      }
    }
  },
  {
    title: "项目名称",
    key: "title",
    width: 200,
    search: true, // 是否在搜索栏展示
  },
  {
    title: "标签",
    key: "tag",
    render(row) {
      try {
        row.tag = row.tag.split(",")
      } catch (e) {

      }
      const jmxxd = []
      row.tag.map(a => {
        jmxxd.push(h(NTag, { class: "ml10", type: "success" }, a))
      })
      return jmxxd
    }
  }, {
    title: "电话",
    key: "phone",
  },
  {
    title: "地址",
    key: "address",
  },


  {
    title: "排序",
    width: 100,
    render(row) {
      row.sjk = "xtgx" //数据库
      row.databaseName = "keyEnterprise"; //表名
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "添加时间",
    key: "addTime",
    width: 150,
  },
];
const qx = {
  DeletePermissionID: "xtgxprojectManagementdel", //删除
  EditPermissionIdentifier: "xtgxprojectManagementbj", // 编辑
  NewPermissionIdentifier: "xtgxprojectManagementxz", // 新建
  ViewPermissionID: "xtgxprojectManagementck", // 查看
};
const portUrl = "xtgx/keyProject";

let formJson = reactive([
  {
    title: "项目名称",
    type: "input",
    required: true, // 是否为必填
    key: "title",
    span: "24"
  },
  {
    title: "所属行业",
    key: "cid",
    type: "select",
    options: [],
    val: 10000
  },
  {
    title: "项目类型",
    key: "xmlx",
    type: "select",
    options: [],
    val: "1",
    callBack(data) {
      bianjis({
        xmlx: data.value
      })
    }
  },
  {
    title: "电话",
    type: "input",
    required: true, // 是否为必填
    key: "phone",
    span: "12"
  },


  {
    title: "标签",
    key: "tag",
    type: "Tags",
    val: [],
    span: "12"
  },
  {
    title: "封面",
    key: "cover",
    type: "img",
    required: true, // 是否为必填
    val: "",
    span: "12"
  },
  {
    title: "pdf文件",
    key: "pdf",
    type: "pdf",
    val: "",
    span: "12"
  },
  {
    title: "园区等级",
    type: "input",
    key: "price",
    span: "12"
  },

  {
    title: "可用土地",
    type: "input",
    required: true, // 是否为必填
    key: "ConstructionTime",
    span: "12",
    dw: "亩"
  },
  {
    title: "地址",
    type: "mapdz",
    required: true, // 是否为必填
    key: "address",
    keyjw: "addressjw",
    span: "24"
  },
  {
    title: "概述",
    key: "summarize",
    type: "fwb",
    span: "24",
  }
]);

const bianjis = (data) => {
  switch (data.xmlx) {
    case '1':
      formJson[7].title = '园区等级';
      formJson[8].title = "可用土地"
      formJson[8].dw = "亩"
      break;
    case '2':
      formJson[7].title = '楼宇级别';
      formJson[8].title = "招商面积"
      formJson[8].dw = "m²"
      break;
    case '3': formJson[7].title = '总投资';
      formJson[8].title = "建设时间"
      formJson[8].dw = "年"
      break;
    case '4': formJson[7].title = '土地性质';
      formJson[8].title = "土地规模"
      formJson[8].dw = "亩"
      break;
  }
}

const czFun = {
  fun: (row) => {

  },
};

const getzdhy = async () => {
  const { data }: any = await dxget("xtgx/api/getzdhy")
  console.log(data);
  dataJson[1].options = [
    {
      label: "全部",
      value: ""
    },
    ...data
  ]
  formJson[1].options = data
  sshhs.value = data
}
getzdhy()

const xtgxxmfl = async () => {
  const { data }: any = await dxget("dxgjAdmin/getzd", { name: 'xtgxxmfl' })
  dataJson[2].options = [
    {
      label: "全部",
      value: ""
    },
    ...data
  ]
  formJson[2].options = data
  xmlxSelect.value = data
  console.log(data);
}
xtgxxmfl()


</script>
<style scoped></style>